package com.ebeijia.filter;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ebeijia.context.RequestResponseContext;
import com.ebeijia.util.LoggerUtil;


/**
 * Created by Yangpengju on 2015/8/19.
 */
public class RequestResponseFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        LoggerUtil.info("request response filter init");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        RequestResponseContext.init((HttpServletRequest) request, (HttpServletResponse) response);
        filterChain.doFilter(request,response);
        RequestResponseContext.clear();
    }

    @Override
    public void destroy() {
        LoggerUtil.info("request response filter destroy");
    }
}
